import * as Router from 'koa-router';
import visitMonthPlanService from '../services/visitMonthPlanService';
import reportFormService from '../services/reportFormService';
import { IRouterContext } from 'koa-router';
import dingTalkApi from 'dingtalk-app/dtalk/DingTalkApi';
import dTalkApi from '../core/dTalkApi';
import dTalkApiUtil from 'dingtalk-app/dtalk/dTalkApiUtil';
//PC端-页面       
let router = new Router();
router.prefix('/api/manage');

//(四)PC端-报表
//(一)出差频率
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcTravelFrequency',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getTravelFrequency(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});

//(二)签到率
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcCheckInRate',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getCheckInRate(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});

//(三)门店拜访进度
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcVisitStoreSchadule',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getVisitStoreSchadule(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});

//(四)已拜访门店拜访达标率
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcReachVisitedStoreRate',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getReach_VisitedStoreRate(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});

//(五)新客户拜访达成率
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcReachNewConsumerRate',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getReach_NewConsumerRate(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});

//(六)客户拜访达成率
//参数startDate:开始日期,endDate:结束日期,character:选取的字段  comment:说明//选的哪一个模块
router.post('/pcReachConsumerRate',async(ctx: IRouterContext, next: any)=>{ 
    let rq:any=ctx.request;
    let res=rq.body;
    let data=await reportFormService.getReachConsumerRate(res.startDate,res.endDate,res.character,res.comment,res.leaderId);
    if(data.length !=0){
        ctx.body=data;
        ctx.status=200;
    }else{
        ctx.body=[];
    } 
    await next()  
});



export default router